$(function () {
    init();
    function init() {
        getcategoryData();
        eventList();
    }

    function eventList() {
        $(".category_list_content").on('tap', '.category_title', function () {
            let titleid = $(this).attr('data-id');
            let that = $(this)
            $.ajax({
                type: "get",
                url: "http://193.112.55.79:9090/api/getcategory",
                data: {
                    titleid: titleid
                },
                dataType: "json",
                success: function (res) {
                    let data = res.result;
                    console.log(data)
                    console.log(data[0].categoryId)
                    let html = ``;
                    for (let i = 0; i < data.length; i++) {
                        html += `<a href="category_detail.html?categoryId=${data[i].categoryId}&category=${data[i].category}">${data[i].category}</a>`
                    }   
                    that.parent().find('.list_info').html(html)

                }
            });
        })
    }
    // 添加请求标题数据
    function getcategoryData() {
        $.get("http://193.112.55.79:9090/api/getcategorytitle", function (res) {
            if (res) {
                let data = res.result;
                let html = ``;
                for (let i = 0; i < data.length; i++) {
                    html += `<li class="mui-table-view-cell mui-collapse">
                    <a class="category_title mui-navigate-right" data-id="${data[i].titleId}" href="javascript:;">${data[i].title}</a>
                    <div class="mui-collapse-content list_info">
                        
                    </div>
                </li>`
                }
                $('.category_list_content').html(html);
            }
        })
    }
})